from django import forms
from .models import MyUser


class LoginForm(forms.Form):
    username = forms.CharField(label="用户名", widget=forms.TextInput(attrs={
        "class": "form-control"
    }))
    password = forms.CharField(label="密码", widget=forms.PasswordInput(attrs={
        "class": "form-control"
    }))

    password2 = forms.CharField(label="再次密码", widget=forms.PasswordInput(attrs={
        "class": "form-control"
    }))

    # 复杂表单


class RegisterForm(forms.ModelForm):
    # 自定义新的字段
    password2 = forms.CharField(label="确认密码", widget=forms.PasswordInput(attrs={
        "class": "form-control",
        "placeholder": "请再次输入密码",
        "id":"password2"

    }))

    # 控制原始模型表单
    class Meta:
        model = MyUser
        # 展示全部信息
        # fields = "__all__"
        # 展示自己想要的信息
        fields = ["username", "password", "email", "phone"]
        # 设置每个字段的属性
        widgets = {
            "username": forms.TextInput(attrs={
                "id": "username",
                "class": "form-control",
                "placeholder": "请输入用户名"
            }),
            "password": forms.PasswordInput(attrs={
                "id": "password",
                "class": "form-control",
                "placeholder": "请输入密码"
            }),
            "email": forms.EmailInput(attrs={
                "id": "email",
                "class": "form-control",
                "placeholder": "请输入电子邮箱"
            }),
            "phone": forms.TextInput(attrs={
                "id": "phone",
                "class": "form-control",
                "placeholder": "请输入手机号"
            })
        }


class UpdatePasswordForm(forms.Form):
    old_password = forms.CharField(label="旧密码", widget=forms.PasswordInput({
        "id": "password0",
        "class": "form-control",
        "placeholder": "请输入旧密码"

    }))
    new_password = forms.CharField(label="新密码", widget=forms.PasswordInput({
        "id": "password1",
        "class": "form-control",
        "placeholder": "请输入新密码"
    }))
    new_password_replace = forms.CharField(label="确认密码", widget=forms.PasswordInput({
        "id": "password2",
        "class": "form-control",
        "placeholder": "请再次输入新密码"
    }))


class CenterForm(forms.ModelForm):

    class Meta:
        model = MyUser
        fields = ["head","username","last_name","first_name","last_login","email","phone","date_joined",]
        # 忽略哪个字段
        exclude = ["password"]
        widgets = {
            "username": forms.TextInput(attrs={
                "id": "username",
                "placeholder": "请输入修改后的用户名",
                "class": "form-control"
            }),
            "last_name": forms.TextInput(attrs={
                "id": "last_name",
                "placeholder": "请输入修改后的姓氏",
                "class": "form-control"
            }),
            "first_name": forms.TextInput(attrs={
                "id": "first_name",
                "placeholder": "请输入修改后的名字",
                "class": "form-control"
            }),
            "last_login": forms.TextInput(attrs={
                "id": "last_login",
                "placeholder": "上次登陆时间",
                "class": "form-control",
                "readonly":True

        }),
            "email": forms.TextInput(attrs={
                "id": "email",
                "placeholder": "请输入修改后的邮箱",
                "class": "form-control"
            }),
            "phone": forms.TextInput(attrs={
                "id": "phone",
                "placeholder": "请输入修改后的手机号",
                "class": "form-control"
            }),
            "date_joined": forms.TextInput(attrs={
                "id": "date_joined",
                "class": "form-control",
                "readonly":True
            })
        }





